// React基础组件
import React from 'react'
// dva 连接组件 - 连接route和model
import { connect } from 'dva'
// 引入antd的组件
import {Form, Modal, Input,message} from 'antd'
//导入路由组件，用于跳转等
import { Link, hashHistory } from 'dva/router'
// 导入项目全局配置文件
import config from 'config/config'

// 引入model取值工具方法
import { mapStateToProps } from 'utils/view_utils'
// 当前组件样式
import styles from './evaluateListStyle.less'
//引用listPage
import ListPage from 'widget/PageTmpl/ListPage'
import cx from 'classnames'
//权限管理
import FlagBtn from 'widget/FlagBtn/FlagView'
const confirm = Modal.confirm
/**
 * description 路由视图及事件处理
 * dispatch 分发到models中的effects对应事件名
 * model 用于获取models中state定义的数据
 * form 表单对象
 */
const evaluateListView = function({dispatch, model, form}) {
    // 表单的子函数
    const {resetFields, getFieldDecorator, validateFields, setFieldsValue} = form
    // 取出model对象，命名空间
    const { modelObj, namespace } = model

    // modelObj.xxx获取model中状态机的值
    let { showModal } = modelObj
    // 评价详情页跳转
    // function checkSkip(id) {
    //     hashHistory.push({
    //         pathname: `/home/evaluateAdmin/evaluateDetail`,
    //         query: { contentId:id }
    //     });
    // }
    // 弹出调整修改分数对话框
    function modifyPoint(){
        dispatch({
            type: `${namespace}/updateStore`,
            payload: { showModal:true }
        });
    }
    //对话框点击ok
    function handleOk (){
        dispatch({
            type: `${namespace}/updateStore`,
            payload: { showModal:false }
        });
    }
    //对话框点击取消
    function handleCancel(){
        dispatch({
            type: `${namespace}/updateStore`,
            payload: { showModal:false }
        });
    }

    //导出
     function downLoad() {
         dispatch({
            type: `${namespace}/downLoad`,
            payload: { }
        });
    }
    //删除
    // function deleteLabel(counselorEvaluateId) {
    //     dispatch({
    //         type: `${namespace}/labelDel`,
    //         payload: { counselorEvaluateId }
    //     });
    // }
    const timeSkip = (row)=>{
        console.log("timeSkip",row)
        confirm({
            title: '确定删除吗?',
            okText: '确认',
            okType: 'primary',
            cancelText: '取消',
            onOk() {
                // 添加成员id userId 项目Id在状态机中获取
                dispatch({ type: `${namespace}/deleteEvaluate`, payload: {ids:row.counselorEvaluateId}  })
            },
            onCancel() {
                console.log('Cancel');
            },
        });
    }
    const timeSkipAll = (row)=>{
        console.log("timeSkip",row)
        let arr = []
        for(var i=0;i<row.length;i++){
            arr.push(row[i].counselorEvaluateId)
        }
        let ids= arr.join(',')
        console.log(ids)
        confirm({
            title: '确定删除吗?',
            okText: '确认',
            okType: 'primary',
            cancelText: '取消',
            onOk() {
                // 添加成员id userId 项目Id在状态机中获取
                dispatch({ type: `${namespace}/deleteEvaluate`, payload: {ids}  })
            },
            onCancel() {
                console.log('Cancel');
            },
        });
    }

    let pageProps = {
        // ---------- 界面部分 ----------
        ui: {
            // 页面接口地址
            api_url: "admin/counselorEvaluate/searchEvaluate",
            // 接口方式
            method: "POST",
            // "data_field_name":"data",
            app: "",
            // 接口参数
            params: "",
            // 模拟数据 - 用于开发需要，若填充了上面的api_url之后，请将此项设置为null
            // "mockData": mockData,
            mockData: null,
            
            // 查询栏
            search_bar: {
                fields: [
                    {
                        en_name: 'productName',
                        zh_name: '项目名称',
                        elem_type: 'Input',
                        elem_valid_type: 'string',
                    },
                    {
                        en_name: 'counselorName',
                        zh_name: '顾问姓名',
                        elem_type: 'Input',
                        elem_valid_type: 'string',
                    },
                    {
                        en_name: 'counselorMobile',
                        zh_name: '顾问电话',
                        elem_type: 'Input',
                        elem_valid_type: 'string',
                    },
                    {
                        en_name: 'evaluateName',
                        zh_name: '评价人姓名',
                        elem_type: 'Input',
                        elem_valid_type: 'string',
                    },
                    {
                        en_name: 'evaluateMobile',
                        zh_name: '评价人电话',
                        elem_type: 'Input',
                        elem_valid_type: 'string',
                    },
                ],
                searchHandler: () => { // 自定义搜索按钮回调函数，点击搜索时触发
                    console.log('search click')
                },
                resetHandler: () => { // 自定义重置按钮回调函数，点击重置时触发
                    console.log('reset click')
                },
                searchCallback: params => { // 自定义搜索完成后的后调函数, 搜索完成后触发, 并将本次搜索的参数传入
                    console.log('search finish', params)
                },
                pasteTargetList: [  // 列表组件中将输入框的en_name作为默认id(也可以通过id另外设置)
                    'channel',  // 将需要粘贴事件拦截的输入框id以数组的形式传入, 该参数对应PasteFromClipboard组件的targetList参数
                ]
            },
            // 数据表格
            table:
                {
                    status_params: "status=0",
                    status_text: "全部",
                    // 表头字段列表
                    scroll: { x: 1100 },
                    fields: [
                        {
                            en_name: "productName",
                            zh_name: "项目名称",
                        },
                        {
                            en_name: "counselorName",
                            zh_name: "顾问姓名",
                             width:100
                        },
                        {
                            en_name: "counselorMobile",
                            zh_name: "顾问电话",
                            width:130
                        },
                        {
                            en_name: "evaluateName",
                            zh_name: "评价人姓名",
                             width:80
                        },
                        {
                            en_name: "evaluateMobile",
                            zh_name: "评价人电话",
                            width:130
                        },
                        {
                            en_name: "stars",
                            zh_name: "评价分数",
                          width:80,
                            render: (a, item, index, d, e, f) => {
                            return (
                                <span>
                                  <span>{item.stars.toFixed(1)}</span>
                                </span>
                            )
                          }
                          
                        },
                        {
                            en_name: "tags",
                            zh_name: "评价标签",
                            width:130,
                            render:(text,row)=>{
                              return (
                                <div>
                                  {row.tags&&<p>{ row.tags }</p>}
                                </div>
                              )
                            }

                        },
                        {
                            en_name: "firstContent",
                            zh_name: "评价内容",
                            render:(text,row)=>{
                              return (
                                <div>
                                  <p>{ text }</p>
                                  {row.appendContent&&<p>{ row.appendContent }</p>}
                                  {/*text + row.appendContent*/}
                                </div>
                              )
                            }

                        },
                        {
                            en_name: "createTime",
                            zh_name: "评价时间",
                            width:180
                        },
                        {
                          en_name: "edit",
                          zh_name: "操作",
                          render: (a, item, index, d, e, f) => {
                            return (
                                <span>
                                   {/*<Popconfirm Collapse title='确定要删除吗？' okText='确定' cancelText='取消' onConfirm={() => { deleteLabel(item.counselorEvaluateId) }}>*/}
                                        {/*<a >删除</a>*/}
                                  {/*</Popconfirm>*/}
                                  <FlagBtn node={<a onClick={() => timeSkip(item,"authorize")}>删除</a>} btnId={'80203'}> </FlagBtn>
                                    {/* <a onClick={() => timeSkip(item,"authorize")}>删除</a>*/}
                                </span>
                            )
                          },
                        }
                    ]
                },
            // 操作栏
            action_bar: [
                {
                    // rowSelection: () => { },
                    func_name: "export",
                    label: "导出",
                    btnId:'80201',
                    type: "primary",
                    onClick: (e) =>{
                        downLoad()
                    }
                },
                {
                    label:'批量删除',
                    btnId:'80202',
                    type:'primary',
                    rowSelection:[],
                    onClick:(e,row)=>{
                        // 自定义点击事件，第二个参数rows为当rowSelection: '1'时，返回选中行的数据数组
                        console.log('rowsrowsrows:', row)
                        if(row.length<=0){
                            message.warn('请选择一项你要选择的项目')
                            return
                        }
                        timeSkipAll(row)
                    }
                },
            ]
        },
    }
    if (!!modelObj.biz) {
        pageProps.biz = modelObj.biz
        pageProps.biz.syncBackCbf = (biz) => {
            //console.log(biz)
            dispatch({
                type: `${namespace}/updateStore`,
                payload: { biz }
            })
        }
    }

    return (
        <div className={cx('pageLayout')}>
            <ListPage pageProps={pageProps}/>
            <Modal
                title="修改显示分数"
                visible={showModal}
                onOk={handleOk}
                onCancel={handleCancel}
                width={300}
            >
                <span>修改分数为：</span>
                <Input style={{width:"100px"}} value={100}></Input>
            </Modal>
        </div>
    )
}

// 连接视图(view)和模型(model)
export default connect(mapStateToProps)(Form.create()(evaluateListView))
